/**
 * 
 */
package pl.kaczanowscy.tomek.ipdl;

import static pl.kaczanowscy.tomek.ipdl.enums.ClassicValue.PUNISHMENT;
import static pl.kaczanowscy.tomek.ipdl.enums.ClassicValue.REWARD;
import static pl.kaczanowscy.tomek.ipdl.enums.ClassicValue.SUCKER;
import static pl.kaczanowscy.tomek.ipdl.enums.ClassicValue.TEMPTATION;
import static pl.kaczanowscy.tomek.ipdl.enums.Move.COOPERATION;
import pl.kaczanowscy.tomek.ipdl.enums.ClassicValue;
import pl.kaczanowscy.tomek.ipdl.enums.Move;

/**
 * A classic game matrix - like the one you will find in the books. This class
 * is a singleton.
 * 
 * @author Tomek Kaczanowski
 * 
 */
public final class ClassicGameMatrix implements GameMatrix {

	private static final GameMatrix INSTANCE = new ClassicGameMatrix();

	private ClassicGameMatrix() {
		// no need to create objects
	}

	/**
	 * Returns singleton.
	 * 
	 * @return singleton
	 */
	public static GameMatrix getInstance() {
		return INSTANCE;
	}

	/**
	 * Returns {@link ClassicValue}s of payoffs.
	 * 
	 * @see pl.kaczanowscy.tomek.ipdl.GameMatrix#getPayoff(pl.kaczanowscy.tomek.ipdl.enums.Move,
	 *      pl.kaczanowscy.tomek.ipdl.enums.Move)
	 */
	@Override
	public int getPayoff(Move moveA, Move moveB) {
		if (moveA == COOPERATION) {
			return (moveB == COOPERATION) ? REWARD.getValue() : SUCKER
					.getValue();
		}
		return (moveB == COOPERATION) ? TEMPTATION.getValue() : PUNISHMENT
				.getValue();
	}

	@Override
	public String toString() {
		StringBuilder result = new StringBuilder();
		result.append("reward for cooperation: ").append(REWARD.getValue());
		result.append(", ");
		result.append("sucker's payoff: ").append(SUCKER.getValue());
		result.append(", ");
		result.append("temptation to defect: ").append(TEMPTATION.getValue());
		result.append(", ");
		result.append("punishment: ").append(PUNISHMENT.getValue());
		return result.toString();
	}
	
	
}
